import request from '@/utils/request'
import { urlPrefix } from './config'
import { formatQuery } from './util'

export function getBatchList(page = 1, params, query) {
  let url = `${urlPrefix}/batch?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get',
    params
  })
}

export function getBatchListByName(params) {
  return request({
    url: `${urlPrefix}/batch/search_name`,
    method: 'get',
    params
  })
}

export function changeInterviewer(id, interviewer) {
  const url = `${urlPrefix}/batch/change_interviewer/${id}`
  return request({
    url: url,
    method: 'patch',
    data: {
      interviewer
    }
  })
}

export function getBatchInterviewList(batch_id, type) {
  return request({
    url: `${urlPrefix}/batch/interview-list/${batch_id}`,
    method: 'get',
    params: { type: type }
  })
}

export function getBatch(id) {
  return request({
    url: `${urlPrefix}/batch/${id}`,
    method: 'get'
  })
}

export function tiaojiList(id, lun = 'first') {
  return request({
    url: `${urlPrefix}/batch/tiaoji_list/${id}`,
    method: 'get',
    params: {
      lun: lun
    }
  })
}

export function doTiaoji(id, batch_id, lun = 'first') {
  return request({
    url: `${urlPrefix}/batch/tiaoji`,
    method: 'patch',
    data: {
      id: id,
      batch_id: batch_id,
      lun: lun
    }
  })
}
